package com.ruoyi.demo.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.demo.domain.TTress;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.bo.TTressQueryBo;
import com.ruoyi.demo.service.ITTressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 古树信息列Controller
 *
 * @author ruoyi
 * @date 2021-10-31
 */
@Api(value = "古树信息列控制器", tags = {"古树信息列管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/demo/tress")
public class TTressController extends BaseController {

    private final ITTressService iTTressService;

	/**
	 * 查询全部古树信息
	 */
	@ApiOperation("查询全部古树信息")
	@GetMapping("/all")
	public AjaxResult all() {
		return AjaxResult.success(iTTressService.list());
	}

	/**
	 * 查询古树信息列列表
	 */
	@ApiOperation("查询古树信息列列表")
	@PreAuthorize("@ss.hasPermi('demo:tress:list')")
	@GetMapping("/list")
	public TableDataInfo<TTress> list(@Validated TTressQueryBo bo) {
		return iTTressService.queryPageList(bo);
	}

    /**
     * 导出古树信息列列表
     */
    @ApiOperation("导出古树信息列列表")
    @PreAuthorize("@ss.hasPermi('demo:tress:export')")
    @Log(title = "古树信息列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TTress> export(@Validated TTressQueryBo bo) {
        List<TTress> list = iTTressService.queryList(bo);
        ExcelUtil<TTress> util = new ExcelUtil<TTress>(TTress.class);
        return util.exportExcel(list, "古树信息列");
    }

    /**
     * 获取古树信息列详细信息
     */
    @ApiOperation("获取古树信息列详细信息")
    @PreAuthorize("@ss.hasPermi('demo:tress:query')")
    @GetMapping("/{id}")
    public AjaxResult<TTress> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Integer id) {
        return AjaxResult.success(iTTressService.queryById(id));
    }

    /**
     * 新增古树信息列
     */
    @ApiOperation("新增古树信息列")
    @PreAuthorize("@ss.hasPermi('demo:tress:add')")
    @Log(title = "古树信息列", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody TTress bo) {
        return toAjax(iTTressService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改古树信息列
     */
    @ApiOperation("修改古树信息列")
    @PreAuthorize("@ss.hasPermi('demo:tress:edit')")
    @Log(title = "古树信息列", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody TTress bo) {
        return toAjax(iTTressService.update(bo) ? 1 : 0);
    }

    /**
     * 删除古树信息列
     */
    @ApiOperation("删除古树信息列")
    @PreAuthorize("@ss.hasPermi('demo:tress:remove')")
    @Log(title = "古树信息列" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Integer[] ids) {
        return toAjax(iTTressService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
